'use strict';

const conn = require('../../../libs/Conn');

module.exports = async function (updateParams) {
    let group_id = updateParams.group_id;
    let checkUserGroupSql = `SELECT ug.group_name FROM user_group ug  WHERE ug.group_name = ? AND ug.group_id != ? AND ug.delete_sign = 1`;
    let repeatData = (await conn(checkUserGroupSql, [updateParams.group_name, group_id])).shift();
    if (repeatData) {
        let repeat = `用户组名称重复`;
        return {success: false, message: repeat};
    } else {
        let updateObj = {
            group_name: updateParams.group_name,
            sys_menu_id: updateParams.sys_menu_id,
            sys_button_id: updateParams.sys_button_id,
            department:updateParams.department_id,
            is_manager:updateParams.sfcg
        };
        let updateSql = `UPDATE user_group ug SET ? WHERE group_id = ?`;
        await conn(updateSql, [updateObj, group_id]);
        return {success: true};
    }
};